import re

class channel:
	def __init__(self, irc):
		self.irc = irc
		self.chanlist = {}

	def add(self, channel):
		if self.chanelist.has_key(channel):
			return False
		else:
			self.chanlist[channel] = []
			return True

	def rem(self, channel):
		if self.chanlist.has_key(channel):
			del self.chanlist[channel]
			return True
		return False

	def isChannel(self, channel):
		m = re.match(self.irc.rfc2812_channel(), channel)
		if m != None:
			return True
		return False
	
	def addNick(self, channel, nick, mode=""):
		if mode == '@' or mode == '+':
			tuple = mode, nick
		tuple = nick

		self.chanlist[channel].append(tuple)
	
	def delNick(self, channel, nick):
		i = int(0)
		for tuple in self.chanlist[channel]:
			tmode, tnick = tuple
			if nick == tnick:
		 		del self.chanlist[channel][i]
				return True
			i += 1
		return False
	
	def inChannel(self, channel, nick):
		for tuple in self.chanlist[channel]:
			tmode, tnick = tuple
			if nick == tnick:
				return True
		return False

	def getMode(self, channel, nick):
		for tuple in self.chanlist[channel]:
			tmode, tnick = tuple
			if nick == tnick:
				return mode
		return None
		 	
